# -*- coding: utf-8 -*-..,
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp import tools

import pytz
import tzlocal
from tzlocal import get_localzone # $ pip install tzlocal

# ?????
#  only can be saving, afterchoosing "Active..."  => ???? 
#
# 
class crea8s_followup(osv.osv):
    _name = "crea8s.followup"
    _description = 'crea8s_followup...'
    _columns = {
        
		'date': fields.date('Date'),
        'ref_detail_id': fields.one2many('crea8s.followup.detail', 'crea8s_followup_ref', 'Details'),
        
        'company_id': fields.many2one('res.company', 'Company', readonly=False),
        'name': fields.related('company_id', 'name', string = "Name", type="char"),
        
# 'state': fields.selection([('draft','Draft'),
# ('confirmed','Confirmed')],'State',required=True,readonly=True)
    }
#     _rec_name = 'partner_id' # ???
#     _auto = False # okok, ??? this object is for reporting purpose.
       
    strFormatTime = '%Y-%m-%d %H:%M:%S %Z'
    def act_helloword(self, cr, uid, ids, context={}):
       return self.write(cr, uid, ids, {'name': 'Hello word ! - PhongND said: "cr, uid, ids"'})
   
    def act_find_odd(self, cr, uid, ids, context={}):
	
        return True
    
    
class crea8s_followup_detail(osv.osv):
    
    def _get_default_template(self, cr, uid, ids, context=None): # ??
        try:
            return self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crea8s_followup', 'email_template_crea8s_followup_default')[1]
        except ValueError:
            return False

    _name = "crea8s.followup.detail"
    _description = 'crea8s_followup_detail.....'
    _columns = {
        'name': fields.char('Follow-up Action', size=256),
        'date': fields.date('Date'),
        'crea8s_followup_ref': fields.many2one('crea8s.followup', 'Follow-up Company'),
        'delay': fields.integer('Delay Days'),
        'manual_action': fields.boolean('Manual Action', help="When processing, it will set the manual action to be taken for that customer. "),
        'send_an_email': fields.boolean('Send an Email', help="When processing, it will send an email"),
        'send_a_letter': fields.boolean('Send a Letter', help="When processing, it will print a letter"),
        'description': fields.text('Description'),
        'email_template_ref': fields.many2one('email.template', 'Email Template'),
    }
    
    _defaults = {
        'send_an_email': True,
#         'send_a_letter': True,
#         'manual_action':False,
        'description': """
        Dear %(partner_name)s,

Exception made if there was a mistake of ours, it seems that the following amount stays unpaid. Please, take appropriate measures in order to carry out this payment in the next 8 days.

Would your payment have been carried out after this mail was sent, please ignore this message. Do not hesitate to contact our accounting department.

Best Regards, - phongnd
""",
    'email_template_ref': _get_default_template,
    }

    
crea8s_followup()
crea8s_followup_detail()





